<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="description" content="">
		<meta name="author" content="">
		<title>订单</title>
		<link rel="stylesheet" href="../../css/base.css" />
		<link rel="stylesheet" href="../../css/common.css" />
		<!-- Bootstrap Core CSS -->
		<link href="../../sbadmin/bower_components/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
		<!-- MetisMenu CSS -->
		<link href="../../sbadmin/bower_components/metisMenu/dist/metisMenu.min.css" rel="stylesheet">
		<!-- DataTables CSS -->
		<link href="../../sbadmin/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.css" rel="stylesheet">
		<!-- Custom CSS -->
		<link href="../../sbadmin/dist/css/sb-admin-2.css" rel="stylesheet">
		<!-- Custom Fonts -->
		<link href="../../sbadmin/bower_components/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" href="../../css/jquery.datetimepicker.css" />
		<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
		<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
		<!--[if lt IE 9]>
	<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
	<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
	<![endif]-->
		<style>
			body {
				padding: 0 15px !important;
			}
			
			.wo-form-itemtt {
				width: 100px;
			}
			
			#dataTables-example_length {
				position: absolute;
				top: -35px;
				left: 30px;
				z-index: 1000;
			}
		</style>
	</head>

	<body style="background:#FFF;">
		<div class="comm-tt-font pr">
			订单
			<a href="add.html" class="add-member-btn">新建订单</a>
		</div>
		<div class="member-search-box">
			<div class="msb-ico">筛选条件</div>
			<div class="msb-ccbox">
				<div class="wo-form-item clb">
					<div class="fl mb10">
						<div class="wo-form-itemtt fl">会员姓名：</div>
						<div class="wo-form-itemcc fl">
							<input type="text" class="item-input" id="memName" />
						</div>
					</div>
					<div class="fl mb10">
						<div class="wo-form-itemtt fl">手机号：</div>
						<div class="wo-form-itemcc fl">
							<input type="text" class="item-input" id="memTel" />
						</div>
					</div>
					<div class="fl mb10">
						<div class="wo-form-itemtt fl">第三方流水号：</div>
						<div class="wo-form-itemcc fl">
							<input type="text" class="item-input" id="" />
						</div>
					</div>
				</div>
				<div class="wo-form-item clb">
					<div class="fl mb10">
						<div class="wo-form-itemtt fl">销售城市：</div>
						<div class="wo-form-itemcc fl">
							<select class="item-select" id="memCity"></select>
						</div>
					</div>
					<div class="fl mb10">
						<div class="wo-form-itemtt fl">销售门店：</div>
						<div class="wo-form-itemcc fl">
							<select class="item-select" id="memShop">

							</select>
						</div>
					</div>
					<div class="fl mb10">
						<div class="wo-form-itemtt fl">商品名：</div>
						<div class="wo-form-itemcc fl">
							<input type="text" class="item-input" id="memGoods" />
						</div>
					</div>
				</div>
				<div class="wo-form-item clb">
					<div class="fl mb10">
						<div class="wo-form-itemtt fl">商品分类：</div>
						<div class="wo-form-itemcc fl">
							<select class="item-select" id="memFl">
							</select>
						</div>
					</div>
					<div class="fl mb10">
						<div class="wo-form-itemtt fl">销售类型：</div>
						<div class="wo-form-itemcc fl">
							<input type="text" class="item-input" id="memType" />
						</div>
					</div>
					<div class="fl mb10">
						<div class="wo-form-itemtt fl">订单号：</div>
						<div class="wo-form-itemcc fl">
							<input type="text" class="item-input" id="memOrderId" />
						</div>
					</div>
				</div>
				<div class="wo-form-item clb">
					<div class="fl mb10">
						<div class="wo-form-itemtt fl">支付日期：</div>
						<div class="wo-form-itemcc fl">
							<input type="text" class="item-input" id="memDate" />
							<label class="z-font">至</label>
							<input type="text" class="item-input" id="memDate2" />
						</div>
					</div>
				</div>
				<div class="clb mt10" style="margin-left: 80px;">
					<a href="javascript:void(0);" id="czBtn" class="fl commqx-btn">重置</a>
					<a href="javascript:void(0);" class="fl commqr-btn ml15" id="orderCfm">确定</a>
				</div>
			</div>
		</div>
		<div class="bars-box pr" style="width: 100%;overflow-x: scroll;">
			<div style="width: 100%;height: 50px;position: relative;">
				<a data-type="xls" class="expbtn fr mt10 mr10" id="export" href="javascript:;">导出列表</a>
			</div>
			<div class="panel-body" style="padding-top: 0 !important;width: 2200px;">
				<div class="dataTable_wrapper" id="app">
					<table class="table table-striped table-bordered table-hover" id="dataTables-example">
						<thead>
							<tr>
								<th>订单号</th>
								<th>第三方流水号</th>
								<th>商品名</th>
								<th>商品分类</th>
								<th>销售类型</th>
								<th>会员姓名</th>
								<th>会员手机号</th>
								<th>收货地址</th>
								<th>销售门店</th>
								<th>应收金额</th>
								<th>实付金额</th>
								<th>支付方式</th>
								<th>销售方式</th>
								<th>支付状态</th>
								<th>支付交易时间</th>
								<th>截至有效期</th>
								<th>订单状态</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="list-td">

						</tbody>
					</table>
				</div>
				<!-- /.table-responsive -->
			</div>
			<div class="no-tit">
				<img class="no-pic" src="../../img/error.jpg" />
				<p class="no-txt">没有符合筛选条件的记录</p>
			</div>
		</div>

		<!-- jQuery -->
		<script src="../../sbadmin/bower_components/jquery/dist/jquery.min.js"></script>
		<!-- Bootstrap Core JavaScript -->
		<script src="../../sbadmin/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<!-- Metis Menu Plugin JavaScript -->
		<script src="../../sbadmin/bower_components/metisMenu/dist/metisMenu.min.js"></script>
		<!-- DataTables JavaScript -->
		<script src="../../sbadmin/bower_components/datatables/media/js/jquery.dataTables.min.js"></script>
		<script src="../../sbadmin/bower_components/datatables-plugins/integration/bootstrap/3/dataTables.bootstrap.min.js"></script>
		<!-- Custom Theme JavaScript -->
		<script src="../../sbadmin/dist/js/sb-admin-2.js"></script>
		<script type="text/javascript" src="../../js/jquery.datetimepicker.full.js"></script>
		<script src="../../js/layer/layer.js"></script>
		<script type="text/javascript" src="../../js/common.js"></script>
		<script type="text/javascript" src="../../js/jquery-ui.min.js"></script>
		<script type="text/javascript" src="../../js/Blob.js"></script>
		<script type="text/javascript" src="../../js/FileSaver.js"></script>
		<script type="text/javascript" src="../../js/tableExport.js"></script>
		<!-- Page-Level Demo Scripts - Tables - Use for reference -->
	</body>
	<script>
		$("#czBtn").click(function() {
			location.reload();
		})
		$.datetimepicker.setLocale('ch'); //转换成中文
		$('#memDate').datetimepicker({
			lang: "ch", //语言选择中文 注：旧版本 新版方法：$.datetimepicker.setLocale('ch');
			format: 'Y-m-d',
			timepicker: true, //关闭时间选项
			yearStart: 2000, //设置最小年份
			yearEnd: 2050, //设置最大年份
			todayButton: false, //关闭选择今天按钮
			step: 5,
			//  startDate: enddate + "-" + "01"
		});
		$('#memDate2').datetimepicker({
			lang: "ch", //语言选择中文 注：旧版本 新版方法：$.datetimepicker.setLocale('ch');
			format: 'Y-m-d',
			timepicker: true, //关闭时间选项
			yearStart: 2000, //设置最小年份
			yearEnd: 2050, //设置最大年份
			todayButton: false, //关闭选择今天按钮
			step: 5,
			//  startDate: enddate + "-" + "01"
		});
		//渲染城市-门店
		$.ajax({
			url: "https://order.wz1996.wang/wzbg/openedcity/all",
			type: 'get',
			contentType: 'application/json',
			beforeSend: function(request) {
				request.setRequestHeader("token", localStorage.getItem("token"));
			},
			success: function(data) {
				console.log(data);
				//登录状态
				var html = "";
				if(data.code == "1") {
					html += "<option value=''>--请选择--</option>"
					for(var i = 0; i < data.data.length; i++) {
						html += "<option id=" + data.data[i].cityId + " value=" + data.data[i].cityId + ">" + data.data[i].cityName + "</option>"
					}
					$("#memCity").html(html);
				} else if(data.code == "-1") {
					layar(data.msg);
					setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
				} else {
					layar(data.msg);
				}
			},
			error: function(e) {
				errcode(e);
			}
		});
		$("#memCity").change(function() {
			var id = $("#memCity option:selected").html();
			var user = {
				"store": {
					"cityName": id
				}
			}
			$.ajax({
				url: "https://order.wz1996.wang/wzbg/store/query",
				type: 'post',
				contentType: 'application/json',
				data: JSON.stringify(user),
				beforeSend: function(request) {
					request.setRequestHeader("token", localStorage.getItem("token"));
				},
				success: function(data) {
					console.log(data)
					if(data.code == "1") {
						var html = "";
						for(var i = 0; i < data.data.length; i++) {
							html += "<option id=" + data.data[i].store.id + " value=" + data.data[i].store.id + ">" + data.data[i].store.name + "</option>"
						}
						$("#memShop").html(html)

					} else if(data.code == "-1") {
						layar(data.msg);
						setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
					} else {
						layar(data.msg);
					}
				},
				error: function(e) {
					errcode(e);
				}
			});

		});
		//销售类型
		$.ajax({
			url: "https://order.wz1996.wang/wzbg/category/album",
			type: 'get',
			contentType: 'application/json',
			beforeSend: function(request) {
				request.setRequestHeader("token", localStorage.getItem("token"));
			},
			success: function(data) {
				console.log(data);
				//登录状态
				var html = "";
				if(data.code == "1") {
					html += "<option value=''>--请选择--</option>"
					for(var i = 0; i < data.data.length; i++) {
						html += "<option id=" + data.data[i].id + " value=" + data.data[i].id + ">" + data.data[i].name + "</option>"
					}
					$("#memFl").html(html);
				} else if(data.code == "-1") {
					layar(data.msg);
					setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
				} else {
					layar(data.msg);
				}
			},
			error: function(e) {
				errcode(e);
			}
		});
		//筛选
		$("#orderCfm").click(function() {
			var name = $("#memName").val();
			var phone = $("#memTel").val();
			var city = $("#memCity option:selected").val();
			var store = $("#memShop option:selected").val();
			var gdsName = $("#memGoods").val();
			var gdsType = $("#memFl option:selected").val();
			var saleType = $("#memType").val();
			var orderNum = $("#memOrderId").val();
			var sdate;
			var edate;
			var sdate = $("#memDate").val();
			var edate = $("#memDate2").val();
			getList(name, phone, city, store, gdsName, gdsType, saleType, orderNum, sdate, edate)
		})

		//getList("小虎", "", "", "", "", "", "", "", "")

		function getList(name, phone, city, store, gdsName, gdsType, saleType, orderNum, sdate, edate) {
			$("#dataTables-example").dataTable().fnDestroy();
			var post_data = {
				"orderDetail": {
					"outTradeNo": orderNum,
					"receiverName": name,
					"receiverPhone": phone,
					"saleType": saleType,
					"skuCategory": gdsType,
					"skuName": gdsName,
					"storeCityId": city,
					"storeId": store,
				},
				"startDate": sdate,
				"endDate": edate
			}
			$.ajax({
				url: "https://order.wz1996.wang/wzbg/order/query",
				type: 'post',
				contentType: 'application/json',
				data: JSON.stringify(post_data),
				beforeSend: function(request) {
					request.setRequestHeader("token", localStorage.getItem("token"));
				},
				success: function(data) {
					console.log(data);
					if(data.code == "1") {
						var html = "";
						for(var i = 0; i < data.data.length; i++) {
							html += "<tr class='odd gradeX'>";
							html += "<td>" + data.data[i].outTradeNo + "</td>";
							html += "<td>" + data.data[i].batch + "</td>";
							html += "<td>" + data.data[i].skuName + "</td>";
							if(data.data[i].skuCategory == 2) {
								html += "<td>儿童</td>";
							} else if(data.data[i].skuCategory == 3) {
								html += "<td>亲子</td>";
							} else if(data.data[i].skuCategory == 4) {
								html += "<td>孕妇</td>";
							} else if(data.data[i].skuCategory == 5) {
								html += "<td>全家福（三代）</td>";
							}
							html += "<td>" + data.data[i].saleType + "</td>";
							html += "<td>" + data.data[i].receiverName + "</td>";
							html += "<td>" + data.data[i].receiverPhone + "</td>";
							if(data.data[i].receiverAddress == "" || data.data[i].receiverAddress == null || data.data[i].receiverAddress == undefined) {
								html += "<td>--</td>";
							} else {
								html += "<td>" + data.data[i].receiverAddress + "</td>";
							}
							if(data.data[i].storeName == "" || data.data[i].storeName == null || data.data[i].storeName == undefined) {
								html += "<td>--</td>";
							} else {
								html += "<td>" + data.data[i].storeName + "</td>";
							}
							html += "<td>" + data.data[i].price + "</td>";
							html += "<td>" + data.data[i].actualPayedPrice + "</td>";
							html += "<td>" + data.data[i].payType + "</td>";
							/*var isOnline = data.data[i].payType;
							var isOnlineType = "";
							if(isOnline == "1") {
								isOnlineType = "微信";
							} else if(isOnline == "2") {
								isOnlineType = "支付宝";
							} else if(isOnline == "3") {
								isOnlineType = "刷卡";
							} else if(isOnline == "4") {
								isOnlineType = "现金";
							}*/
							//html += "<td>---</td>";
							if(data.data[i].isOnline == "1") {
								html += "<td>线上</td>";
							} else {
								html += "<td>线下</td>";
							}
							if(data.data[i].status == "1" || data.data[i].status == "3") {
								html += "<td>已支付</td>";
							} else {
								html += "<td>--</td>";
							}
							html += "<td>" + data.data[i].createTime + "</td>";
							html += "<td>" + data.data[i].expired + "</td>";
							var expired = data.data[i].expired;
							var myDate = new Date(); //获取系统当前时间
							var mytime = myDate.toLocaleString(); //获取当前时间
							var oDate1 = new Date(expired);
							var oDate2 = new Date(mytime);
							if(data.data[i].status == "3") {
								html += "<td>停止</td>";
							} else if(data.data[i].status == "1") {
								html += "<td>有效</td>";
							} else if(oDate1.getTime() < oDate2.getTime()) {
								html += "<td>过期</td>";
							}
							if(data.data[i].status == "3") {
								html += "<td><a href='javascript:void(0)' class='ml10 qiY' id='" + data.data[i].id + "'>启用</a></td>";
							} else {
								html += "<td><a href='javascript:void(0)' class='ml10 ting' id='" + data.data[i].id + "'>停用</a></td>";
							}

							html += "</tr>";
						}
						$("#list-td").html(html);
						$('#dataTables-example').DataTable({
							responsive: false,
							bLengthChange: true,
							aLengthMenu: [
								[10, 25, 50, 100, -1],
								[10, 25, 50, 100, "所有"]
							], // 定义每页显示数据数量
							bSort: true,
							paging: true,
							bFilter: true,
							searching: false,
							bInfo: true,
							bAutoWidth: true,
							"oLanguage": {
								"sLengthMenu": "每页显示 _MENU_ 条记录",
								"sZeroRecords": "抱歉， 没有找到",
								"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
								"sInfoEmpty": "没有数据",
								"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
								"oPaginate": {
									"sFirst": "首页",
									"sPrevious": "前一页",
									"sNext": "后一页",
									"sLast": "尾页"
								},
								"sSearch": "查询条件:",
								"sZeroRecords": "没有检索到数据",
								"sProcessing": "<img src='./loading.gif' />"
							}
						});
					} else if(data.code == "-1") {
						layar(data.msg);
						setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
					} else {
						layar(data.msg);
					}

				},
				error: function(e) {
					errcode(e);
				}
			});

		}
		$("#list-td").on("click", ".ting", function() {
			var orderId = $(this).attr("id");
			layer.confirm('您确定停用吗？', {
				btn: ['确定', '取消'], //按钮
				offset: '25%'
			}, function(index) {
				$.ajax({
					url: "https://order.wz1996.wang/wzbg/order/invalid/" + orderId,
					type: 'put',
					beforeSend: function(request) {
						request.setRequestHeader("token", localStorage.getItem("token"));
					},
					contentType: 'application/json',
					success: function(data) {
						console.log(data);
						//登录状态
						if(data.code == "1") {
							layar("停用成功");
							setTimeout("window.location.href='list.html'", 1000)
						} else if(data.code == "-1") {
							layar(data.msg);
							setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
						} else {
							layar(data.msg);
						}
					},
					error: function(e) {
						errcode(e);
					}
				});
			});

		})
		$("#list-td").on("click", ".qiY", function() {
			var orderId = $(this).attr("id");
			layer.confirm('您确定启用吗？', {
				btn: ['确定', '取消'], //按钮
				offset: '25%'
			}, function(index) {
				$.ajax({
					url: "https://order.wz1996.wang/wzbg/order/reuse/" + orderId,
					type: 'put',
					beforeSend: function(request) {
						request.setRequestHeader("token", localStorage.getItem("token"));
					},
					contentType: 'application/json',
					success: function(data) {
						console.log(data);
						//登录状态
						if(data.code == "1") {
							layar("启用成功");
							setTimeout("window.location.href='list.html'", 1000)
						} else if(data.code == "-1") {
							layar(data.msg);
							setTimeout("window.parent.frames.location.href='/xcxadmin/login.html'", 1000)
						} else {
							layar(data.msg);
						}
					},
					error: function(e) {
						errcode(e);
					}
				});
			});

		})
	</script>

</html>